package com.icreate.storm.methods.indicators;

import com.icreate.entity.indicator.IndicatorID;
import com.icreate.entity.indicator.Uufield;
import com.icreate.storm.methods.common.DateMethod;
import org.apache.storm.tuple.Values;

/**
 * Created by hadoop on 17-5-3.
 */
public class UuIndicator extends BaseIndicator {
    public static final String typeName = "uu";

    @Override
    public String getTypeName() {
        return typeName;
    }

    public static final String[] fields = {"type", "cellid", "imsi", "imei", "IndicatorID",
            "uu.rrc_connect_request", "uu.rrc_connect_success",
            "uu.sm_activate_request", "uu.sm_activate_success",
            "uu.rrc_reconfig_request", "uu.rrc_reconfig_success",
            "uu.rrc_reconstruction_request", "uu.rrc_reconstruction_success",
            "uu.rrc_release_request", "uu.rrc_release_success",
            "uu.cell_inter_request", "uu.cell_inter_success",
            "uu.station_inter_request", "uu.station_inter_success",
            "uu.station_intra_request", "uu.station_intra_success",
            "uu.rat_in_request", "uu.rat_in_success",
            "uu.rat_out_request", "uu.rat_out_success",
            "uu.ps_paging_request", "uu.ps_paging_success",
            "uu.cs_paging_request", "uu.cs_paging_success",
            "uu.otherevent_request", "uu.otherevent_success"
    };
    public static final String[] baseFields = {
            "uu.rrc_connect_request", "uu.rrc_connect_success",
            "uu.sm_activate_request", "uu.sm_activate_success",
            "uu.rrc_reconfig_request", "uu.rrc_reconfig_success",
            "uu.rrc_reconstruction_request", "uu.rrc_reconstruction_success",
            "uu.rrc_release_request", "uu.rrc_release_success",
            "uu.cell_inter_request", "uu.cell_inter_success",
            "uu.station_inter_request", "uu.station_inter_success",
            "uu.station_intra_request", "uu.station_intra_success",
            "uu.rat_in_request", "uu.rat_in_success",
            "uu.rat_out_request", "uu.rat_out_success",
            "uu.ps_paging_request", "uu.ps_paging_success",
            "uu.cs_paging_request", "uu.cs_paging_success",
            "uu.otherevent_request", "uu.otherevent_success"
    };

    @Override
    public String[] getBaseFields() {
        return baseFields;
    }

    public String[] getFields() {
        return fields;
    }

    public Values getValues(Object s) {
        Uufield field = (Uufield) s;

        long status = getValue(field.getStatus());
        boolean valid = true;
        if (field.getStatus().equals(""))
            valid = false;

//        if (cells.length < 17)
//            return null;
//        if (ts.equals("") || cellid.equals("") || imsi.equals(""))
//            return null;
        Values values = new Values("uu", field.getCellid(), field.getImsi(), field.getImei(), field);
        long procedureType = getValue(field.getProcedureType());
        for (long i = 1; i <= 13; i++) {
            if (!valid) {
                values.add(0);
                values.add(0);
                continue;
            }
            values.add(getRequest(i, procedureType));
            values.add(getSuccess(i, procedureType, status));
        }
        return values;
    }

    private long getRequest(long type, long procedureType) {
        if (procedureType == type)
            return 1;
        else
            return 0;
    }

    private long getSuccess(long type, long procedureType, long status) {
        if (procedureType == type && status == 0)
            return 1;
        else
            return 0;
    }


}
